package com.miles.service.impl;

import com.miles.dao.CompanyMapper;
import com.miles.dto.Company;
import com.miles.service.ICompany;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class CompanyService implements ICompany {
    @Autowired
    private CompanyMapper companyMapper;

    public List<Company> queryCompany(Company company) {
        List<Company> compList = new ArrayList<Company>();
        String sql = "select * from company where 1=1";
        if(company.getUser()!=null)
            sql+=" and user = '"+ company.getUser()+"'";
        if(company.getCompany()!=null)
            sql+=" and company = '"+company.getCompany()+"'";
        compList = companyMapper.query(sql);
        return compList;
    }

    public int addCompany(Company company){
        return companyMapper.add(company.getUser(),company.getCompany());
    }
}
